#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2018/10/12 9:50
@desc
"""

import re, urllib2

fp = open("thebigproxylist-18-10-12.txt", 'r')
lines = fp.readlines()

for ip in lines:
    try:
        print("当前代理IP " + ip)
        proxy = urllib2.ProxyHandler({'http': ip})
        opener = urllib2.build_opener(proxy)
        urllib2.install_opener(opener)

        url = "http://www.baidu.com"
        request = urllib2.Request(url)
        request.add_header('User-Agent', 'fake-client')
        response = urllib2.urlopen(request, timeout=5)

        # print(response.read())

        # opener = urllib.request.build_opener(proxy, urllib.request.HTTPHandler)
        # urllib.request.install_opener(opener)
        # data = urllib.request.urlopen(url).read().decode('utf-8', 'ignore')
        print("通过")

        print("-----------------------------")
    except Exception as err:
        print(err)
        print("-----------------------------")

fp.close()
